package demo6;

import java.time.LocalDateTime;

//显示当前日期，格式为“2019年01月01日 周一 01时01分01秒” 采用两种方式实现,
//不允许使用String.format
//思路二:

public class DisplayDate02 {public static void main(String[] args) {
    System.out.println(format(LocalDateTime.now()));
    System.out.println(format(LocalDateTime.now().plusDays(1)));
    System.out.println(format(LocalDateTime.now().plusDays(2)));
}
    public static String ws = " 一二三四五六日";
    public static String format(LocalDateTime d) {
        StringBuilder sb = new StringBuilder();
        sb.append(d.getYear());
        sb.append('年');
        if(d.getMonth().getValue()<10) {
            sb.append('0');
        }
        sb.append(d.getMonthValue());
        sb.append('月');
        if(d.getDayOfMonth()<10) {
            sb.append('0');
        }
        sb.append(d.getDayOfMonth());
        sb.append("日 周");
        sb.append(ws.charAt(d.getDayOfWeek().getValue()));
        // sb.append(d.getDayOfWeek().getValue());
        sb.append(' ');
        if(d.getHour()<10) {
            sb.append('0');
        }
        sb.append(d.getHour());
        sb.append("时");
        if(d.getMinute()<10) {
            sb.append('0');
        }
        sb.append(d.getMinute());
        sb.append("分");
        if(d.getSecond()<10) {
            sb.append('0');
        }
        sb.append(d.getSecond());
        sb.append("秒");
        return sb.toString();
    }

}
